package com.rc.web.controller;

import com.rc.pojo.dto.address.AddressAddDTO;
import com.rc.pojo.dto.address.AddressUpdateDTO;
import com.rc.pojo.vo.address.AddressVO;
import com.rc.web.service.AddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/address")
@RequiredArgsConstructor
@Api(tags = "地址")
public class AddressController {
    private final AddressService addressService;

    @PostMapping
    @ApiOperation("新增")
    public void add(@RequestBody AddressAddDTO dto) {
        addressService.add(dto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public void deleteOneById(@PathVariable Long id){
        addressService.deleteOneById(id);
    }

    @PutMapping
    @ApiOperation("修改")
    public void updateOneById(@Validated @RequestBody AddressUpdateDTO dto){
        addressService.updateOneById(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation("详情")
    public AddressVO getOneById(@PathVariable Long id) {
        return addressService.getOneById(id);
    }

    @GetMapping("/list")
    @ApiOperation("列表")
    public List<AddressVO> getList(){
        return addressService.getList();
    }
}
